<?php
namespace Admin\Controller;
use Think\Controller;
/**公共操作控制器**/
class PublicController extends Controller {
	//用户登录
	public function login(){
		if(IS_POST){
			//dump($_POST);exit();
			$member = D('Member');
			if($member->check_login($_POST)){
				$this->success('登录成功',U('Index/index'));
			}else{
				// dump($member->getError());die;
				$this->error($member->getError());
			}
		}else{
			$this->display();
		}
	}

	//用户退出
	public function logout(){
		session('user',null);
        redirect('login');

	}

	//找回密码
	public function zhaohui(){
		//验证用户名和邮箱
		$username = I('username2');
		$email = I('email');
		$model = M('Member');
		$user = $model->where(array('username'=>$username))->find();
		if(!$user){$this->error('用户名不存在或者被禁用');}
		if($user['email'] != $email){
			$this->error('填写邮箱账号错误');
		}
		$linkurl = U('Public/change_password',array('userid'=>$user['id']));
		$url = 'http://api.sendcloud.net/apiv2/mail/send';
       /* $API_USER = 'U37WJSPsGThg9lOs';
        $API_KEY = 'Va_Dly_test_Fyumqj';
		$param = array(
			'apiUser'=>$API_USER,
			'apiKey'=>$API_KEY,
            'from' => 'dlyzjs@163.com', # 发信人，用正确邮件地址替代
            'fromName' => '火妹游戏官方平台',
            'to' => 'roots@maskerphp.cc',# 收件人地址, 用正确邮件地址替代, 多个地址用';'分隔  
            'subject' => '找回密码',
            'html' => '请点击该链接进行生成新密码'.$linkurl,
            'respEmailId' => 'true'
        );
        $data = http_build_query($param);
        $options = array(
            'http' => array(
                'method' => 'POST',
                'header' => 'Content-Type: application/x-www-form-urlencoded',
                'content' => $data
        ));
        $context  = stream_context_create($options);
        $result = file_get_contents($url, FILE_TEXT, $context);*/
		$this->success('未开放');
	}


	//修改密码
	public function change_password(){
		if(IS_POST){
			$newpassword = I('post.newpassword');
			$userid = intval(I('post.userid'));
			$data['password']= md5($newpassword);
			$user = M('Member')->where(array('id'=>$userid))->save($data);
			if(!$user){
				$this->error('修改失败');
			}else{
				$this->success('修改成功',U('Public/login'));
			}

		}
	}




}